package nl.wubinator.aeve.xmlconverters.standard.parsers;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;

import nl.wubinator.aeve.models.standard.alliancelist.Alliance;

import org.xml.sax.Attributes;

import android.util.Log;

public class AllianceParser {
	public static Alliance parseAttributes(Attributes atts) {
		Alliance alliance = new Alliance();
		
		try {
			DateFormat dateFormatter = new SimpleDateFormat(
					"yyyy/dd/mm HH:mm:ss");
			// The character consists of the following attributes:
			// - name
			// - shortName
			// - allianceID
			// - executorCorpID
			// - memberCount
			// - startDate
			alliance.setName(atts.getValue("name"));
			alliance.setShortName(atts.getValue("shortName"));
			alliance.setAllianceID(Integer.parseInt(atts.getValue("allianceID")));
			alliance.setExecutorCorpID(Integer.parseInt(atts
					.getValue("executorCorpID")));
			alliance.setMemberCount(Integer.parseInt(atts
					.getValue("memberCount")));
			alliance.setStartDate(dateFormatter.parse(atts
					.getValue("startDate")));
		} catch (ParseException e) {
			Log.e("Parsing date failed:", e.getMessage());
		}

		return alliance;
	}
}
